﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LIMS.BLL
{
    public class LabOrderManager
    {
        private static IDAL.ILabOrder orderLab = DALFactory.DataAccessFactory<LIMS.IDAL.ILabOrder>.CreateOrderLab();


        /// <summary>
        /// 添加一条预约实验室数据
        /// </summary>
        /// <param name="order">待添加的实验室预约数据</param>
        /// <returns>添加成功返回true</returns>
        public static Boolean AddLabOrderInfo(LIMS.Model.OrderLabs order)
        {
            return orderLab.InsertOrderInfo(order);
        }

        /// <summary>
        /// 检查实验室在指定条件下是否已经被预约
        /// </summary>
        /// <param name="order"></param>
        /// <returns></returns>
        public static Boolean CheckOrdered(LIMS.Model.OrderLabs order)
        {
            return orderLab.IsCanOrder(order.orderTestDate, order.labID, order.orderClassTimeSpan);
        }

        /// <summary>
        /// 未完成，，更新实验室预约数据
        /// </summary>
        /// <param name="order"></param>
        /// <returns></returns>
        public static Boolean UpdateLabOrder(LIMS.Model.OrderLabs order)
        {
            return orderLab.Modify(order);
        }

        /// <summary>
        /// 获取所有预约总项数
        /// </summary>
        /// <returns></returns>
        public static Int32 GetOrderCount()
        {
            return orderLab.TotalOrders();
        }

        /// <summary>
        /// 多种查询预约实验室数据的查询条件组合
        /// </summary>
        /// <returns></returns>
        public static List<LIMS.Model.OrderLabs> Search(DateTime orderTestTime, String labID = "", String teacherID = "", Model.OrderClassTimeSpan orderClassTimeSpan = Model.OrderClassTimeSpan.None, String strDetail = "")
        {
            if (orderTestTime != null && orderTestTime.Date != DateTime.Now.Date)
            {
                return orderLab.FindByTestTime(orderTestTime);
            }
            if (!String.IsNullOrWhiteSpace(labID))
            {
                return orderLab.FindByLabID(labID);
            }
            if (!String.IsNullOrWhiteSpace(teacherID))
            {
                return orderLab.FindByTeacherID(teacherID);
            }
            if (orderClassTimeSpan != Model.OrderClassTimeSpan.None)
            {
                return orderLab.FindByClassTime(orderClassTimeSpan);
            }
            if (!String.IsNullOrWhiteSpace(strDetail))
            {
                return orderLab.FindByDetail(strDetail);
            }
            return orderLab.FindAll();
        }

        private static List<LIMS.Model.OrderLabs> GetOrders()
        {
            return orderLab.FindAll();
        }


        public static List<LIMS.Model.OrderLabs> GetAllOrder()
        {
            return orderLab.FindAll();
        }
    }
}
